home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / AppMaker 2.0b3 / Demo AppMaker 2.0b3 / Examples / pre-built AMReminder / PowerPlant / CAMReminderData.cp < prev    next >
Encoding:
Text File  |  1995-10-05  |  3.6 KB  |  191 lines  |  [TEXT/MMCC]

  1. // CAMReminderData.cp -- document data
  2. // Created 10/5/95 4:49 PM by AppMaker
  3.  
  4. // The purpose of the Data module is to shield the rest of your application
  5. // from your internal data structures and the representation of your files.
  6. // The Data module provides an abstract interface to the contents of your files.
  7.  
  8. #include "CAMReminderData.h"
  9.  
  10. #include <LFileStream.h>
  11.  
  12. //----------
  13. // initialize application data
  14.  
  15. void    CAMReminderData::InitAppData()
  16. {
  17. }
  18.  
  19. // ---------------------------------------------------------------------------
  20. //        • CAMReminderData
  21. // ---------------------------------------------------------------------------
  22.  
  23. CAMReminderData::CAMReminderData()
  24.         :LBroadcaster()
  25. {
  26.     mFile = nil;
  27.     mDirty = false;
  28. }
  29.  
  30. // ---------------------------------------------------------------------------
  31. //        • ~CAMReminderData
  32. // ---------------------------------------------------------------------------
  33. //    Destructor
  34. //
  35.  
  36. CAMReminderData::~CAMReminderData()
  37. {
  38.     CloseFile();
  39. }
  40.  
  41. //----------
  42. void    CAMReminderData::newData()
  43. {
  44.     CreateData();
  45.     initDocData();
  46. }
  47.  
  48. //----------
  49. void    CAMReminderData::openData    (FSSpec        *inMacFSSpec)
  50. {
  51.     mFile = OpenFile (inMacFSSpec);
  52.     initDocData();
  53.     ReadData();
  54. }
  55.  
  56. //----------
  57. void    CAMReminderData::initDocData()
  58. {
  59. }
  60.  
  61. //----------
  62. Boolean    CAMReminderData::IsDirty()
  63. {
  64.     return mDirty;
  65. }
  66.  
  67. //----------
  68. void    CAMReminderData::DoSave()
  69. {
  70.     WriteData(mFile);
  71. }
  72.  
  73. //----------
  74. void    CAMReminderData::DoSaveAs    (FSSpec        *inMacFSSpec)
  75. {
  76.     LFileStream        *file;
  77.  
  78.     file = CreateFile(inMacFSSpec);
  79.     if (file != nil) {
  80.         WriteData(file);
  81.         CloseFile();    // old file
  82.         mFile = file;
  83.     }
  84. }
  85.  
  86. //----------
  87. void    CAMReminderData::DoRevert()
  88. {
  89.     DisposeData();
  90.     if (mFile != nil) {
  91.         ReadData();
  92.     }
  93. }
  94.  
  95. //----------
  96. void    CAMReminderData::CloseFile()
  97. {
  98.     if (mFile != nil) {
  99.         delete mFile;
  100.         mFile = nil;
  101.     }
  102. }
  103.  
  104. //----------
  105. // CreateFile is called in two situations:
  106. // 1. To Save a new untitled document
  107. // 2. To SaveAs to a new file
  108.  
  109. LFileStream        *CAMReminderData::CreateFile    (FSSpec        *inMacFSSpec)
  110. {
  111.     LFileStream        *file = new LFileStream(*inMacFSSpec);
  112.  
  113.     file->CreateNewDataFile(kSignature, kFileType);
  114.     file->OpenDataFork(fsRdWrPerm);
  115.  
  116.     return file;
  117. }
  118.  
  119. //----------
  120. LFileStream        *CAMReminderData::OpenFile        (FSSpec        *inMacFSSpec)
  121. {
  122.     LFileStream        *file = new LFileStream(*inMacFSSpec);
  123.  
  124.     file->OpenDataFork(fsRdWrPerm);
  125.  
  126.     return file;
  127. }
  128.  
  129. // The next few methods are for transferring data between the
  130. // data file and your internal data structures, and for disposing
  131. // your data structures. They are called by Open, Close, etc.
  132. // Replace their bodies with whatever is suitable for your application
  133.  
  134. // define internal data structures to describe the file format:
  135.  
  136. //----------
  137. typedef struct
  138. {
  139.     int            stuff;
  140.  
  141. } AMReminderData;
  142.  
  143. //----------
  144. void    CAMReminderData::CreateData()
  145. {
  146.     // initialize your data structures
  147. }
  148.  
  149. //----------
  150. void    CAMReminderData::DisposeData()
  151. {
  152.     // delete your data structures
  153.  
  154.     mDirty = false;
  155. }
  156.  
  157. //----------
  158. void    CAMReminderData::ReadData()
  159. {
  160.     // read all or part of the file into your data structures
  161. }
  162.  
  163. //----------
  164. // WriteData is called in two situations:
  165. // 1. To Save the current document
  166. // 2. To SaveAs to a new file
  167.  
  168. void    CAMReminderData::WriteData        (LFileStream    *file)
  169. {
  170.     // write from your data structures to the file
  171.  
  172.     mDirty = false;
  173. }
  174.  
  175. // The remaining methods are for accessing your data as logical chunks.
  176. // These are just models for your own accessor functions;
  177. // they aren't called by any AppMaker-generated code.
  178. // Replace them with whatever is suitable for your application.
  179.  
  180. //----------
  181. void    CAMReminderData::GetStuff    (void*        stuff)
  182. {
  183. }
  184.  
  185. //----------
  186. void    CAMReminderData::SetStuff    (void*        stuff)
  187. {
  188. }
  189.  
  190. // AMReminderData.cp
  191.